package com.xinli.xinlifm.mvp.model;

import com.xinli.xinlifm.http.bean.CategoryBean;
import com.xinli.xinlifm.http.bean.DianTaiBean;
import com.xinli.xinlifm.http.bean.ForumBean;
import com.xinli.xinlifm.http.bean.FroumDetailCommentBean;
import com.xinli.xinlifm.http.bean.HomeBean;
import com.xinli.xinlifm.http.bean.find.FindCircleBean;
import com.xinli.xinlifm.http.bean.find.FindXinChangBean;
import com.xinli.xinlifm.http.bean.find.FindZhuBean;
import com.xinli.xinlifm.http.bean.player.MoreBean;
import com.xinli.xinlifm.http.bean.player.PlayerBean;
import com.xinli.xinlifm.http.bean.player.RecommendBean;
import com.xinli.xinlifm.http.server.BaseServer;
import com.xinli.xinlifm.http.server.SuperServer;

import org.greenrobot.eventbus.EventBus;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * 只要有数据就调用
 * 封装的不太好，见谅！！
 * <p>
 * Created by zz on 16-10-12.
 */

public class SuperModel extends MvpModel {
    public void getModelData() {
        Call<HomeBean> homeBean = BaseServer.getApi(SuperServer.class).getHomeBean();
        homeBean.enqueue(new Callback<HomeBean>() {
            @Override
            public void onResponse(Call<HomeBean> call, Response<HomeBean> response) {
                EventBus.getDefault().post(response.body());
            }

            @Override
            public void onFailure(Call<HomeBean> call, Throwable t) {

            }
        });
    }


    /**
     *      没写注释的都别改，具体看地址，比如这个flag传个0就好了
     *
     * @param flag
     * @param offset
     *              刷新用的
     * @param limit
     * @param type
     *      社区精华 type=1
     *      社区最新 type =0
     */
    public void getForumData( int flag,int offset, int limit,int type){

        Call<ForumBean> forumBean = BaseServer.getApi(SuperServer.class).getForumBean(flag, offset, limit, type);
        forumBean.enqueue(new Callback<ForumBean>() {
            @Override
            public void onResponse(Call<ForumBean> call, Response<ForumBean> response) {
                EventBus.getDefault().post(response.body());
            }

            @Override
            public void onFailure(Call<ForumBean> call, Throwable t) {
                t.printStackTrace();
            }
        });
    }


    public void getDetailCommentData(int post_id, int offset, int limit){

        Call<FroumDetailCommentBean> detailCommentBeanCall = BaseServer.getApi(SuperServer.class).getDetailComment(post_id,offset,limit);
        detailCommentBeanCall.enqueue(new Callback<FroumDetailCommentBean>() {
            @Override
            public void onResponse(Call<FroumDetailCommentBean> call, Response<FroumDetailCommentBean> response) {
                EventBus.getDefault().post(response.body());
            }

            @Override
            public void onFailure(Call<FroumDetailCommentBean> call, Throwable t) {

            }
        });
    }
    public void getCategoryData(int category_id, int offset, int limit, String key) {
        Call<CategoryBean> categoryBean = BaseServer.getApi(SuperServer.class).getCategoryBean(category_id, offset, limit, key);
        categoryBean.enqueue(new Callback<CategoryBean>() {
            @Override
            public void onResponse(Call<CategoryBean> call, Response<CategoryBean> response) {
                EventBus.getDefault().post(response.body());
            }

            @Override
            public void onFailure(Call<CategoryBean> call, Throwable t) {
                t.printStackTrace();
            }
        });
    }

    public void getNewLessonData(int offset, int limit, String key) {
        Call<CategoryBean> newLessonBean = BaseServer.getApi(SuperServer.class).getNewLessonBean(offset, limit, key);
        newLessonBean.enqueue(new Callback<CategoryBean>() {
            @Override
            public void onResponse(Call<CategoryBean> call, Response<CategoryBean> response) {
                EventBus.getDefault().post(response.body());
            }

            @Override
            public void onFailure(Call<CategoryBean> call, Throwable t) {
                t.printStackTrace();
            }
        });

    }

    public void getNewFMData(int offset, int limit, String key) {
        Call<CategoryBean> newFm = BaseServer.getApi(SuperServer.class).getNewFm(offset, limit, key);
        newFm.enqueue(new Callback<CategoryBean>() {
            @Override
            public void onResponse(Call<CategoryBean> call, Response<CategoryBean> response) {
                EventBus.getDefault().post(response.body());
            }

            @Override
            public void onFailure(Call<CategoryBean> call, Throwable t) {
                t.printStackTrace();
            }
        });
    }


    public void getDianTaiData(String key) {
        Call<DianTaiBean> dianTai = BaseServer.getApi(SuperServer.class).getDianTai(key);
        dianTai.enqueue(new Callback<DianTaiBean>() {
            @Override
            public void onResponse(Call<DianTaiBean> call, Response<DianTaiBean> response) {
                EventBus.getDefault().post(response.body());
            }

            @Override
            public void onFailure(Call<DianTaiBean> call, Throwable t) {
                t.printStackTrace();
            }
        });
    }

    /**
     * find 的轮播下载
     */
    public void getFindCircleData() {
        Call<FindCircleBean> findCircleBean = BaseServer.getApi1(SuperServer.class).getFindCircleBean();
        findCircleBean.enqueue(new Callback<FindCircleBean>() {
            @Override
            public void onResponse(Call<FindCircleBean> call, Response<FindCircleBean> response) {
                EventBus.getDefault().post(response.body());
            }

            @Override
            public void onFailure(Call<FindCircleBean> call, Throwable t) {

            }
        });
    }

    /**
     * find下面的6主播头像
     */
    public void getFindZhuData(){
        Call<FindZhuBean> findZhuBean = BaseServer.getApi(SuperServer.class).getFindZhuBean();
        findZhuBean.enqueue(new Callback<FindZhuBean>() {
            @Override
            public void onResponse(Call<FindZhuBean> call, Response<FindZhuBean> response) {
                EventBus.getDefault().post(response.body());
            }

            @Override
            public void onFailure(Call<FindZhuBean> call, Throwable t) {

            }
        });
    }

    /**
     * find下面的6主播头像
     */
    public void getFindXinChang(String tag,int offset){
        Call<FindXinChangBean> findXinChangBean = BaseServer.getApi1(SuperServer.class).getFindXinChangBean(tag,offset);
        findXinChangBean.enqueue(new Callback<FindXinChangBean>() {
            @Override
            public void onResponse(Call<FindXinChangBean> call, Response<FindXinChangBean> response) {
                EventBus.getDefault().post(response.body());
            }

            @Override
            public void onFailure(Call<FindXinChangBean> call, Throwable t) {

            }
        });
    }

    /**
     * 音乐播放器的数据
     * @param id
     */
    public void getPlayer(int id){
        Call<PlayerBean> playerBean = BaseServer.getApi(SuperServer.class).getPlayerBean(id);
        playerBean.enqueue(new Callback<PlayerBean>() {
            @Override
            public void onResponse(Call<PlayerBean> call, Response<PlayerBean> response) {
                EventBus.getDefault().post(response.body());
            }

            @Override
            public void onFailure(Call<PlayerBean> call, Throwable t) {

            }
        });
    }

  public void getRecommendData(int offset,int broadcast_id,int limit){
        Call<RecommendBean> recommendBean = BaseServer.getApi(SuperServer.class).getRecommendBean(offset, broadcast_id, limit);
        recommendBean.enqueue(new Callback<RecommendBean>() {
            @Override
            public void onResponse(Call<RecommendBean> call, Response<RecommendBean> response) {
                EventBus.getDefault().post(response.body());
            }

            @Override
            public void onFailure(Call<RecommendBean> call, Throwable t) {

            }
        });
    }

}
